#pragma once

#ifndef SINGLETON_H
#define SINGLETON_H

namespace Tvimeg
{
	template<class SingletonType>
	class Singleton
	{
	public:
		static void Create(void)
		{
			Destroy();
			instance = new SingletonType();
		}

		static void Destroy(void)
		{
			delete instance;
			instance = 0;

		}

		static bool IsAvailable(void)
		{
			return instance != 0;
		}

		static SingletonType& GetInstance(void)
		{
			return *instance;
		}

	protected:
		Singleton(void)
		{
		}

		~Singleton(void)
		{
		}

	private:
		static SingletonType*		instance;
	};

	template<class SingletonType> SingletonType* Singleton<SingletonType>::instance = 0;
}

#endif // SINGLETON_H
